package _11_整理题目._1_链表指针._翻转链表;

import org.junit.Test;
import util.ListNode;

public class _00_链表中点拆分 {
    
    public ListNode middle(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;
        while (fast.next!=null && fast.next.next!=null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        return slow;
    }
    
    @Test
    public void main() {
        Integer[] ins1 = {1,2,3,4};
        ListNode l1 = ListNode.getListFromArray(ins1);
        ListNode mid1Before = middle(l1);
        ListNode mid1 = mid1Before.next;
        mid1Before.next = null;
        ListNode.printList(l1);
        ListNode.printList(mid1);
        
        Integer[] ins2 = {1,2,3,4,5};
        ListNode l2 = ListNode.getListFromArray(ins2);
        ListNode mid2Before = middle(l2);
        ListNode mid2 = mid2Before.next;
        mid2Before.next = null;
        ListNode.printList(l2);
        ListNode.printList(mid2);
    }
}
